#include "ServerRun.h"
#include "Network/ServerRoot.h"
#include "Log.h"
#include <iostream>

#include "GameSingleton.h"
#include "ServerConfigure.h"
#include "Network/ServerRoot.h"
#include "GameRandom.hpp"


namespace PocketSurvival
{
    void Run()
    {
        const std::string serverLogo = "      _____           _        _         \n     |  __ \\         | |      | |        \n     | |__) |__   ___| | _____| |_       \n     |  ___/ _ \\ / __| |/ / _ \\ __|      \n     | |  | (_) | (__|   <  __/ |_       \n   __|_|   \\___/ \\___|_|\\_\\___|\\__|    _ \n  / ____|                (_)          | |\n | (___  _   _ _ ____   _____   ____ _| |\n  \\___ \\| | | | '__\\ \\ / / \\ \\ / / _` | |\n  ____) | |_| | |   \\ V /| |\\ V / (_| | |\n |_____/ \\__,_|_|    \\_/ |_| \\_/ \\__,_|_|\n                                         \n                                         ";
        // const std::string serverLogo = "    ██████╗  ██████╗  ██████╗██╗  ██╗███████╗████████╗        \n    ██╔══██╗██╔═══██╗██╔════╝██║ ██╔╝██╔════╝╚══██╔══╝        \n    ██████╔╝██║   ██║██║     █████╔╝ █████╗     ██║           \n    ██╔═══╝ ██║   ██║██║     ██╔═██╗ ██╔══╝     ██║           \n    ██║     ╚██████╔╝╚██████╗██║  ██╗███████╗   ██║           \n    ╚═╝      ╚═════╝  ╚═════╝╚═╝  ╚═╝╚══════╝   ╚═╝           \n                                                              \n███████╗██╗   ██╗██████╗ ██╗   ██╗██╗██╗   ██╗ █████╗ ██╗     \n██╔════╝██║   ██║██╔══██╗██║   ██║██║██║   ██║██╔══██╗██║     \n███████╗██║   ██║██████╔╝██║   ██║██║██║   ██║███████║██║     \n╚════██║██║   ██║██╔══██╗╚██╗ ██╔╝██║╚██╗ ██╔╝██╔══██║██║     \n███████║╚██████╔╝██║  ██║ ╚████╔╝ ██║ ╚████╔╝ ██║  ██║███████╗\n╚══════╝ ╚═════╝ ╚═╝  ╚═╝  ╚═══╝  ╚═╝  ╚═══╝  ╚═╝  ╚═╝╚══════╝\n                                                              ";
        std::cout << "\nVERSION: " << APP_VERSION << " , BUILD TIME: " << __DATE__ << " " << __TIME__ << "\n\n" << serverLogo << std::endl;

        GameSingleton::singletonPtr = new SimpleSingleton;
        GameSingleton::serverRoot = GameSingleton::singletonPtr->registerSingleton<ServerRoot>();

        GameSingleton::serverRoot->serverRun();

        delete GameSingleton::singletonPtr;
        GameSingleton::singletonPtr = nullptr;
    }

    void Stop()
    {
        GameSingleton::serverRoot->serverStop();
    }

    void TerminalMessage(const std::string &message)
    {
        GameSingleton::serverRoot->addTerminalMessage(message);
    }
} // namespace PocketSurvival
